export interface TaskEntity {
  id?: number | string
  title?: string
  description?: string
  content?: string
  endTime?: number | string
  type?: TaskType
  bounty?: number
  userId?: string
  bountyNum?: number
  distance?: string
  isLiked?: boolean
  isCollected?: boolean
  createdBy?: number
  createdTime?: number | string
  createdName?: string
  updatedBy?: number
  updatedTime?: number
  updatedName?: string
  delFlag?: number
  taskCommentVO?: any
  images?: any[]
}

export interface Pagination {
  pageSize: number
  pageNum: number
  total: number
}
/**
 * 任务类型(0交流贴 1任务贴 2求助贴 3个人或他人主页贴 4个人或他人评论贴 5热门贴 6收藏贴 7关注贴)
 */
export enum TaskType {
  chat = 0,
  TASK = 1,
  HELP = 2,
  HOMEPAGE = 3,
  COMMENT = 4,
  HOT = 5,
  COLLECT = 6,
  FOLLOW = 7,
}

export const apiTask = {
  /**
   * 任务帖子列表
   * @returns
   */
  list(params?: any): Promise<any> {
    return api.page(
      {
        url: 'demand/task/page',
        params: params, // 将参数传递给 API 调用
      },
      { pageSize: params.pageSize, pageNum: params.pageNum },
    ) as Promise<any>
  },
  /**
   * 任务帖子查询
   * @param params
   * @returns
   */
  findById(id: string | number): Promise<any> {
    return api.action({
      url: `demand/task/getTask/${id}`,
    })
  },
  /**
   * 任务帖子新增
   * @param data
   * @returns
   */
  add: (data: TaskEntity): Promise<any> => {
    return api.add({
      url: 'demand/task/save',
      data,
    })
  },
  /**
   * 任务帖子修改
   * @param data
   * @returns
   */
  update: (data: TaskEntity): Promise<any> => {
    return api.update({
      url: 'demand/task/update',
      data,
    })
  },
  /**
   * 任务帖子删除
   * @param taskList
   * @returns
   */
  delete: (params: any): Promise<any> => {
    return api.delete({
      url: 'demand/task/delete',
      params,
    })
  },
  /**
   * 点赞/取消赞
   * @param params
   * @returns
   */
  likeTask: (id: string|number): Promise<any> => {
    return api.request({
      url: `demand/task/likeTask/${id}`,
    })
  },
  /**
   * 收藏/取消收藏
   * @param params
   * @returns
   */
  collectTask: (id: string|number): Promise<any> => {
    return api.request({
      url: `demand/task/collectTask/${id}`,
    })
  },
  /**
   * 领取任务/取消任务/完成任务
   * @param params
   * @returns
   */
  updateTaskStatus: (params:{type:number,taskId:string|number}): Promise<any> => {
    return api.request({
      url: `demand/task/updateTaskStatus/${params.type}/${params.taskId}`,
    })
  },
  /**
   * 全局搜索
   * @param params
   * @returns
   */
  getDataBySearchKey: (params:any): Promise<any> => {
    return api.page(
      {
        url: 'demand/task/page',
        params: params, // 将参数传递给 API 调用
      },
      { pageSize: params.pageSize, pageNum: params.pageNum },
  )
  }
}
